<?php

namespace App\Http\Controllers\System\Common;

use App\Http\Controllers\System\SystemController;
use Illuminate\Http\Request;
use Ramsey\Uuid\Uuid;

class CaptchaController extends SystemController
{
    /**
     * @param Request $request
     * @return array
     * @throws \Psr\SimpleCache\InvalidArgumentException
     * @throws \Exception
     */
    function show(Request $request) {
        $config = $request->get('config', 'default');
        if (!\Config::has("captcha.{$config}")){
            abort(404);
        }
        $captcha = \Captcha::create($config, true);
        $uuid = Uuid::uuid4();
        \Cache::set(sprintf('Captcha:%s', $uuid), $captcha['key'], 180);
        return [
            'sensitive' => $captcha['sensitive'],
            'uuid' => $uuid,
            'image' => $captcha['img']
        ];
    }
}
